//
//  FindViewController.m
//  WNZSSQ
//
//  Created by JDKJ on 2018/12/3.
//  Copyright © 2018年 JDKJ. All rights reserved.
//

#import "FindViewController.h"
#import "FindView.h"
#import "FindContentViewController.h"
#import "ChannelManageViewController.h"

@interface FindViewController ()<UITableViewDelegate,UITableViewDataSource>

/**
 //数据源
 */
@property(nonatomic,strong)NSMutableArray *dataArr;


/**
 tableView
 */
@property(nonatomic,weak)UITableView *tableView;

@end

@implementation FindViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"";
    
    //左侧
    [self showLeftTitleWithTitle:@"发现" withColor:CSWhiteColor];
    
    //右侧
    UIButton *cancleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cancleButton.frame = CGRectMake(0, 0, 80, 40);
    [cancleButton setTitle:@"去挣钱" forState:UIControlStateNormal];
    cancleButton.titleLabel.font = kFont16;
    [cancleButton setImage:@"金币"];
    [cancleButton setTitleColor:CSWhiteColor forState:UIControlStateNormal];
//    [cancleButton addTarget:self action:@selector(getMoney) forControlEvents:UIControlEventTouchUpInside];
    [cancleButton imageOnTheTitleLeftWithSpace:5];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:cancleButton];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    
    FindView *headView = [[FindView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 40)];
    [self.view addSubview:headView];
    [headView.addBtn addTarget:self action:@selector(add)];
    [self tableView];
    
   
}



#pragma mark - 懒加载

-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        
        _dataArr = [NSMutableArray array];
        
    }
    
    return _dataArr;
}

-(UITableView *)tableView
{
    if (!_tableView) {
        
        UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        
        tableView.delegate=self;
        
        tableView.dataSource=self;
        
        tableView.backgroundColor = [UIColor clearColor];;
        
        tableView.estimatedRowHeight = 150;
        tableView.showsVerticalScrollIndicator = NO;
        [self.view addSubview:tableView];
        
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.right.bottom.mas_equalTo(self.view);
            make.top.mas_equalTo(self.view).offset(40);
            
        }];
        
//        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
        //注册
        [tableView registerClass:[FindViewCellOne class] forCellReuseIdentifier:@"cell1"];
        [tableView registerClass:[FindViewCellTwo class] forCellReuseIdentifier:@"cell2"];
        [tableView registerClass:[FindViewCellThire class] forCellReuseIdentifier:@"cell3"];
        [tableView registerClass:[FindViewCellFour class] forCellReuseIdentifier:@"cell4"];
        
        
        _tableView = tableView;
    }
    return _tableView;
}

#pragma mark - UITableViewDataSource

//行数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

//列数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count + 10;
}

//cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if (indexPath.row % 3 == 0) {
        FindViewCellOne *oneCell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
        oneCell.selectionStyle = 0;
        return oneCell;
    }
    else if (indexPath.row % 3 == 1) {
        FindViewCellTwo *twoCell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
        twoCell.selectionStyle = 0;
        return twoCell;
    }
    else if (indexPath.row % 3 == 2) {
        FindViewCellThire *thireCell = [tableView dequeueReusableCellWithIdentifier:@"cell3"];
        thireCell.selectionStyle = 0;
        return thireCell;
    }else
    {
        FindViewCellFour *fourCell = [tableView dequeueReusableCellWithIdentifier:@"cell3"];
        
        return fourCell;
    }
    
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return CGFLOAT_MIN;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return CGFLOAT_MIN;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc]initWithFrame:CGRectZero];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[UIView alloc]initWithFrame:CGRectZero];
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当离开某行时，让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    FindContentViewController *contentVC = [[FindContentViewController alloc]init];
    [self.navigationController pushViewController:contentVC animated:YES];
    
}

#pragma mark - 频道管理
-(void)add
{
    ChannelManageViewController *manageVC = [[ChannelManageViewController alloc]init];
    [self.navigationController pushViewController:manageVC animated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
